/**
 * 
 */
package com.axt.dbaudit.action.cfg;

import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.axt.dbaudit.bean.cfg.TargetDBBean;
import com.axt.dbaudit.model.cfg.TargetDB;
import com.axt.soa.action.BaseAction;
import com.axt.soa.msg.types.MsgParam;

public class TargetDBAction extends BaseAction{
	private TargetDBBean targetDBBean = new TargetDBBean();
	private List<TargetDB> targetDBs = null;
	
	@JSON(name="targetdbs")
	public List<TargetDB> getTargetDBs() {
		return targetDBs;
	}
	public void setTargetDBs(List<TargetDB> targetDBs) {
		this.targetDBs = targetDBs;
	}
	
	@JSON(name="errcode")
	public int getErrcode() {
		return errcode;
	}
	
	@JSON(name="errinfo")
	public String getErrinfo() {
		return errinfo;
	}
	
	
	private int au_isEnable; //是否启用
	private String au_IP;  //审计服务器IP
	private String au_port; //审计服务器的端口
	private String au_Name; //审计服务器的名称
	private String au_ServerID; //审计服务器所在 的serverid
	private String au_dbname; //返回数据时使用的数据库类型名称
	private String au_Otherport;//应用服务器
	private String au_firewall_port;//防火墙端口
	
	private int au_Deleted; //是否删除了
	private String au_DBType;  //前台发送数据库类型
	/**
	 * @return the au_isEnable
	 */
	public int getAu_isEnable() {
		return au_isEnable;
	}
	/**
	 * @param au_isEnable the au_isEnable to set
	 */
	public void setAu_isEnable(int au_isEnable) {
		this.au_isEnable = au_isEnable;
	}
	/**
	 * @return the au_IP
	 */
	public String getAu_IP() {
		return au_IP;
	}
	/**
	 * @param au_IP the au_IP to set
	 */
	public void setAu_IP(String au_IP) {
		this.au_IP = au_IP;
	}
	/**
	 * @return the au_port
	 */
	public String getAu_port() {
		return au_port;
	}
	/**
	 * @param au_port the au_port to set
	 */
	public void setAu_port(String au_port) {
		this.au_port = au_port;
	}
	/**
	 * @return the au_Name
	 */
	public String getAu_Name() {
		return au_Name;
	}
	/**
	 * @param au_Name the au_Name to set
	 */
	public void setAu_Name(String au_Name) {
		this.au_Name = au_Name;
	}
	/**
	 * @return the au_ServerID
	 */
	public String getAu_ServerID() {
		return au_ServerID;
	}
	/**
	 * @param au_ServerID the au_ServerID to set
	 */
	public void setAu_ServerID(String au_ServerID) {
		this.au_ServerID = au_ServerID;
	}
	/**
	 * @return the au_dbname
	 */
	public String getAu_dbname() {
		return au_dbname;
	}
	/**
	 * @param au_dbname the au_dbname to set
	 */
	public void setAu_dbname(String au_dbname) {
		this.au_dbname = au_dbname;
	}
	/**
	 * @return the au_Otherport
	 */
	public String getAu_Otherport() {
		return au_Otherport;
	}
	/**
	 * @param au_Otherport the au_Otherport to set
	 */
	public void setAu_Otherport(String au_Otherport) {
		this.au_Otherport = au_Otherport;
	}
	/**
	 * @return the au_firewall_port
	 */
	public String getAu_firewall_port() {
		return au_firewall_port;
	}
	/**
	 * @param au_firewall_port the au_firewall_port to set
	 */
	public void setAu_firewall_port(String au_firewall_port) {
		this.au_firewall_port = au_firewall_port;
	}
	/**
	 * @return the au_Deleted
	 */
	public int getAu_Deleted() {
		return au_Deleted;
	}
	/**
	 * @param au_Deleted the au_Deleted to set
	 */
	public void setAu_Deleted(int au_Deleted) {
		this.au_Deleted = au_Deleted;
	}
	/**
	 * @return the au_DBType
	 */
	public String getAu_DBType() {
		return au_DBType;
	}
	/**
	 * @param au_DBType the au_DBType to set
	 */
	public void setAu_DBType(String au_DBType) {
		this.au_DBType = au_DBType;
	}
	
	/**
	 * 获取审计服务器列表
	 */
	public String getTargetDBList()
	{
		setTargetDBs(targetDBBean.getTargetDBList("12"));
		setErrcode(targetDBBean.getErrcode());
		setErrinfo(targetDBBean.getErrinfo());
		
		return MsgParam.SUCCESS;
	}
	/**
	 * 添加审计服务器
	 */
	public String addTargetDB()
	{
		TargetDB targetDB = new TargetDB();
		targetDB.setAu_Name(au_Name);
		targetDB.setAu_DBType(au_DBType);
		targetDB.setAu_IP(au_IP);
		targetDB.setAu_port(au_port);
		targetDB.setAu_firewall_port(au_firewall_port);
		targetDB.setAu_Otherport(au_Otherport);
		targetDB.setAu_Deleted(au_Deleted);
		targetDB.setAu_isEnable(au_isEnable);
	     
		targetDBBean.AddTargetDB(serverPath, targetDB);
		setErrcode(targetDBBean.getErrcode());
		setErrinfo(targetDBBean.getErrinfo());
		
		return MsgParam.SUCCESS;
   }
	/**
	 * 删除给定Id的审计服务器
	 */
	public String deleteTargetDB()
	{
		targetDBBean.DeleteTargetDB(serverPath, au_ServerID);
		setErrcode(targetDBBean.getErrcode());
		setErrinfo(targetDBBean.getErrinfo());
		
		return MsgParam.SUCCESS;
	}
	/**
	 * 更新审计服务器
	 */
	public String updateTargetDB()
	{
		TargetDB targetDB = new TargetDB();
		targetDB.setAu_Name(au_Name);
		targetDB.setAu_DBType(au_DBType);
		targetDB.setAu_IP(au_IP);
		targetDB.setAu_port(au_port);
		targetDB.setAu_firewall_port(au_firewall_port);
		targetDB.setAu_Otherport(au_Otherport);
		targetDB.setAu_Deleted(au_Deleted);
		targetDB.setAu_isEnable(au_isEnable);
	    
		targetDBBean.UpdateTargerDB(serverPath, targetDB);
		
		setErrcode(targetDBBean.getErrcode());
		setErrinfo(targetDBBean.getErrinfo());
		
		return MsgParam.SUCCESS;
		
	}
}
